package cn.da.shuai.cool.ai.search.client.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/spring/ai")
public class ChatController {

    private final ChatClient chatClient;

    public ChatController(ChatClient.Builder builder) {
        this.chatClient = builder.build();
    }

    @GetMapping(value="/hello")
    public String hello() {
        return "你好";
    }

    @GetMapping(value="/chat", produces = "text/html;charset=utf-8")
    public Flux<String> chat(String question) {
        return chatClient.prompt(question).stream().content();
    }
}
